package com.grom.dao;

import java.util.List;

import com.grom.po.Department;
import com.grom.util.IDCreator;
import com.holder.DBContextHolder;
import com.holder.DBUTil;

public class DepartmentDaoImpl implements DepartmentDao {

	public List<Department> getAllDepartments() {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.select(Department.class);
	}

	public List<Department> selectByCondition(String sql) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.getResult(sql, Department.class);
	}

	public Department getDepartmentByID(String id) {
		String sql = "select * from department where id='" + id + "'";
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		List<Department> result = DBUTil.getResult(sql, Department.class);
		return result.get(0);
	}

	public void add(Department department) {
		department.setID(IDCreator.getSingleId());
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.save(department);
	}

	public void update(Department department) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.update(department);
	}

	public void delete(Department department) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.delete(department);
	}

}
